/* ------------------------------------------
*   Copyright (c) [2022] [R.H.Shen]
*   [SC4AC] is licensed under Mulan PSL v2.
*   You can use this software according to the terms and conditions of the Mulan
*   PSL v2.
*   You may obtain a copy of Mulan PSL v2 at:
*              http://license.coscl.org.cn/MulanPSL2
*   THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY
*	KIND, EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO
*	NON-INFRINGEMENT, *	MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
*   See the Mulan PSL v2 for more details.
---------------------------------------------- */

#ifndef _COMMOM__HPP_
#define _COMMOM__HPP_

#include <stdio.h>
#include <stdlib.h>
#include <time.h>

#include <iostream>
#include <string>
#include <vector>

// unistd.h 是 C 和 C++ 程序设计语言中提供对 POSIX 操作系统 API
// 的访问功能的头文件的名称
#include <unistd.h>  //getopt

#include <cmath>

#include "Serial.h"

using namespace std;

#define MAX_SDI_PACKET_SIZE 4 * 6

// 消息类型定义

#define ACFLY_TAKEOFF 1
#define ACFLY_TOUCHDOWN 2
#define ACFLY_LOCK 3
#define ACFLY_FLS 4
#define ACFLY_FLD 5
#define ACFLY_READY 6
#define ACFLY_TAKEOFFOK 7
#define ACFLY_LOCKOK 8
#define ACFLY_FLOK 9
#define ACFLY_SENT_PARM 10
#define ACFLY_RECHECK 11

// 单精度浮点数转化成4字节数组
void FloatToByte(float value, unsigned char *bytes, int size = 4);

// uart接收
// 参数: Serial &s, int &msg_type, float msg[], int &msg_length
bool uart_receive(Serial &s, int &msg_type, float msg[], int &msg_l);

// uart发送
// 参数: Serial &s, int msg_type, float msg[], int msg_l
void uart_send(Serial &s, int msg_type, float msg[], int msg_l);

//=============== GPIO相关函数=======================

#endif
